package shili;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * ConfigManager
 *
 * @author boy
 * @since 2023/10/25
 */
public class ConfigManager {

    /**
     * 恶汉模式
     */
    private static ConfigManager configManager=new ConfigManager();
    private static Properties properties;
    private ConfigManager(){
        String configFile="database.properties";
        properties=new Properties();
        InputStream is=ConfigManager.class.getClassLoader().getResourceAsStream(configFile);
        try{
            properties.load(is);
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 对外提供的获取configmanager实例方法
     * @return
     */
    public static synchronized ConfigManager getInstance(){
        //如果configmanager不存在就创建一个，存在直接返回
        if (configManager==null){
            configManager=new ConfigManager();
        }
        return configManager;
    }

/*   /**
     * 恶汉
     * @return
     *//*
    public static ConfigManager getInstance(){
        return configManager;
    } */
    /**
     * 读取配置文件信息
     */
    public String getValue(String key){
        return properties.getProperty(key);
    }
}
